package com.ruoyi.web.controller.coronary;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.coronary.domain.CoronaryStaff;
import com.ruoyi.coronary.service.ICoronaryStaffService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工Controller
 *
 * @author wky
 * @date 2024-02-06
 */
@RestController
@RequestMapping("/coronary/staff")
@Tag(name = "【员工】管理")
public class CoronaryStaffController extends BaseController
{
    @Autowired
    private ICoronaryStaffService coronaryStaffService;

    /**
     * 查询员工列表
     */
    @Operation(summary = "查询员工列表")
    @PreAuthorize("@ss.hasPermi('coronary:staff:list')")
    @GetMapping("/list")
    public TableDataInfo list(CoronaryStaff coronaryStaff)
    {
        startPage();
        List<CoronaryStaff> list = coronaryStaffService.selectCoronaryStaffList(coronaryStaff);
        return getDataTable(list);
    }

    /**
     * 导出员工列表
     */
    @Operation(summary = "导出员工列表")
    @PreAuthorize("@ss.hasPermi('coronary:staff:export')")
    @Log(title = "员工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CoronaryStaff coronaryStaff)
    {
        List<CoronaryStaff> list = coronaryStaffService.selectCoronaryStaffList(coronaryStaff);
        ExcelUtil<CoronaryStaff> util = new ExcelUtil<CoronaryStaff>(CoronaryStaff.class);
        util.exportExcel(response, list, "员工数据");
    }

    /**
     * 获取员工详细信息
     */
    @Operation(summary = "获取员工详细信息")
    @PreAuthorize("@ss.hasPermi('coronary:staff:query')")
    @GetMapping(value = "/{jobNumber}")
    public AjaxResult getInfo(@PathVariable("jobNumber") String jobNumber)
    {
        return success(coronaryStaffService.selectCoronaryStaffByJobNumber(jobNumber));
    }

    /**
     * 新增员工
     */
    @Operation(summary = "新增员工")
    @PreAuthorize("@ss.hasPermi('coronary:staff:add')")
    @Log(title = "员工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CoronaryStaff coronaryStaff)
    {
        return toAjax(coronaryStaffService.insertCoronaryStaff(coronaryStaff));
    }

    /**
     * 修改员工
     */
    @Operation(summary = "修改员工")
    @PreAuthorize("@ss.hasPermi('coronary:staff:edit')")
    @Log(title = "员工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CoronaryStaff coronaryStaff)
    {
        return toAjax(coronaryStaffService.updateCoronaryStaff(coronaryStaff));
    }

    /**
     * 删除员工
     */
    @Operation(summary = "删除员工")
    @PreAuthorize("@ss.hasPermi('coronary:staff:remove')")
    @Log(title = "员工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jobNumbers}")
    public AjaxResult remove(@PathVariable( name = "jobNumbers" ) String[] jobNumbers)
    {
        return toAjax(coronaryStaffService.deleteCoronaryStaffByJobNumbers(jobNumbers));
    }
}
